<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>请假审批</title>
    <link rel="shortcut icon" href="/img/favicon.ico" /><!--标签页面顶部的小图标-->
    <script th:src="@{/webjars/jquery/3.3.1/jquery.js}"></script>
    <link th:href="@{/webjars/bootstrap/4.0.0/css/bootstrap.css}" rel="stylesheet"/>
    <script th:src="@{/webjars/bootstrap/4.0.0/js/bootstrap.js}"></script>
    <script>
        function findQingJiaByUjName(){
            $.ajax({
                url:"/qingJia/findQingJiaByUtjName.do",
                type:"get",
                data:{ujName:$("#loginName").attr("value")},
                success:function (result) {
                    var tbody = $("#tbody");
                    if (result==null){
                        tbody.append("<tr><td colspan='7'><h2>暂无学生请假记录！</h2></td></tr>");
                    }else {
                        for (var i = 0; i < result.length; i++) {
                            var qingJia = result[i];
                            var state = "";
                            var qTimeFrom = new Date(qingJia.qTimeFrom);
                            var qTimeTo = new Date(qingJia.qTimeTo);
                            var qDays = "七天及以上";
                            if (qingJia.qUjFlag==1) {
                                state = "<span><font color='green'>已准假</font></span>";
                            } else if (qingJia.qUjFlag==2){
                                state = "<span><font color='red'>不同意</font></span>";
                            }else {
                                state = "<span><button class='btn btn-primary btn-sm' value='"+qingJia.qId+"' flag='1' onclick='stateChange(this)'>同意</button>" +
                                    "&nbsp;<button class='btn btn-warning btn-sm' value='"+qingJia.qId+"' flag='2' onclick='stateChange(this)'>不同意</button></span>";
                            }
                            tbody.append("<tr><td>"+(i+1)+"</td>\n" +
                                "         <td>"+qingJia.usName+"</td>\n" +
                                "         <td><textarea cols='40' rows='2' readonly>"+qingJia.qText+"</textarea></td>\n" +
                                "         <td>"+qDays+"</td>\n" +
                                "         <td>"+qTimeFrom.getFullYear()+"-"+(qTimeFrom.getMonth()+1)+"-"+qTimeFrom.getDate()+"&nbsp;"+qTimeFrom.getHours()+":"+qTimeFrom.getMinutes()+":"+qTimeFrom.getSeconds()+"</td>\n" +
                                "         <td>"+qTimeTo.getFullYear()+"-"+(qTimeTo.getMonth()+1)+"-"+qTimeTo.getDate()+"&nbsp;"+qTimeTo.getHours()+":"+qTimeTo.getMinutes()+":"+qTimeTo.getSeconds()+
                                "         <td>"+state+"</td>\n" +
                                "</td></tr>")
                        }
                    }
                },
                error:function () {
                    alert("系统异常");
                }
            })
        }

        $(function () {
            findQingJiaByUjName();
        })

        function stateChange(qId) {
            var state = 2;
            if ($(qId).attr("flag")==1){
                state = 1;
            }
            $.ajax({
                url:"/qingJia/qUtjFlagChange.do",
                type:"get",
                data:{qUjFlag:state,qId:$(qId).val(),qUtFlag:null},
                success:function (result) {
                    if (state==1){
                        $(qId).parent("span").html("<font color='green'>已准假</font>");
                    }else {
                        $(qId).parent("span").html("<font color='red'>不同意</font>");
                    }
                },
                error:function () {
                    alert("系统异常");
                }
            })

        }
    </script>
</head>
<body>
<div th:include="bar/header::header_bar"></div>
<div style="height: 190px;width: 100%;background-color: blueviolet">
    <img src="/img/banner/请假banner.png" style="width: 100%;height: 190px;background-repeat: no-repeat">
</div>
<div style="width: 100%;height: 60px;float: left"></div>
<div style="margin-left: 15%;border: solid 1px #cccccc;width: 70%;height: 40px;float: left">
    <div style="float: left;height: 100%;width: 100px;background-color: #088038;text-align: center"><div style="margin-top: 8px"><font color="white">请假审批</font></div></div>
    <div style="float: right;height: 100%;width: auto">
        <div style="margin-top: 8px">
            <font>
                当前位置:
                <a th:href="@{/index.html}">网站首页</a>&nbsp;>
                请假审批&nbsp;&nbsp;
            </font>
        </div>
    </div>
</div>
<div style="width: 100%;height: 40px;float: left"></div>
<br>
<div>
    <table border="1" class="table table-striped" style="width: 70%" align="center">
        <thead>
        <tr style="text-align: center">
            <td><b>序号</b></td>
            <td><b>请假申请人</b></td>
            <td><b>请假原因</b></td>
            <td><b>请假天数</b></td>
            <td><b>请假开始时间</b></td>
            <td><b>请假结束时间</b></td>
            <td><b>是否同意</b></td>
        </tr>
        </thead>
        <tbody id="tbody"></tbody>
    </table>
</div>
<br><br><br><br><br>
<div th:include="bar/footBar::foot_bar"></div>
</body>
</html>